#pragma once

#include "global_var.h"
#include "Object2D.h"
#include "Image.h"
#include "Randomizer.h"
#include "RealTimeController.h"
#include "Scene.h"
#include "SceneManager.h"
#include "ScreenText.h"
#include "Sprite.h"
#include "Vector2D.h"
#include "ScoreSystem.h"

#include <iostream>
using namespace std;

using namespace Pulpy;

#define CountTime 15.0f
#define GameEndCountDown 3.0f
#define PlayTime 60.0f
#define SlipSpeed 1.5f
#define MaxBanana 10

#define BackGroundMovingSpeed 0.1f

class CatchTheGarbage : public Scene
{
private:
	// Player 1 info
	Object2D Player1;									// Object of player
	bool Player1Jump;									// Controlling player to jump or not to
	float Player1MoveSpeed;						// Controlling how fast player moves
	Vector2D<float> Player1JumpSpeed;	// Controlling how high player jumps
	float P1Score;											// Score for Player 1
	Sprite * P1Sprite[3];								// Sprite for Shadow image
	int P1Index;												// Index controlling sprite animation
	int P1State;												// State that player 1 is current at
	bool P1Slipping;										// Check if player is colliding with banana

	// Player 2 info
	Object2D Player2;									// Object of player
	bool Player2Jump;									// Controlling player to jump or not to
	float Player2MoveSpeed;						// Controlling how fast player moves
	Vector2D<float> Player2JumpSpeed;	// Controlling how high player jumps
	float P2Score;											// Score for Player 2
	Sprite * P2Sprite[3];								// Sprite for Sonic image
	int P2Index;												// Index controlling sprite animation
	int P2State;												// State that player 2 is current at
	bool P2Slipping;										// Check if player is colliding with banana

	// 1 if player 1 wins, 2 if player 2 wins, 0 for draw
	int PlayerWins;

	// Objects
	Object2D Floor;
	Object2D FloatFloorLeft;
	Object2D FloatFloorRight;
	Object2D FloatFloorCenter;
	Object2D BackGround;
	Object2D SignalPage;								// For starting count down and end game 
	Object2D WaterFlow;								// For water flow animation, non solid object
	
	// Objects for HUD
	Object2D P1Score_Word;						// To print the word "P1 Score:"
	Object2D P1Score_Tenth;						// To print tenth position of the score for Player 1
	Object2D P1Score_One;							// To print one position of the score for Player 1
	Object2D P2Score_Word;						// To print the word "P2 Score:"
	Object2D P2Score_Tenth;						// To print tenth position of the score for Player 2
	Object2D P2Score_One;							// To print one position of the score for Player 2
	Object2D Time_Word;								// To print the word "Time"
	Object2D Time_Tenth;								// To print tenth position of the score for time
	Object2D Time_One;								// To print one position of the score for time

	// Objects for points
	Object2D Point_1;
	Object2D Point_2;

	// Items in the game
	Object2D Garbage;
	Object2D BonusGarbage[5];
	Object2D Banana[MaxBanana];

	// Textures
	TextureImage Image_CountDown[5];
	TextureImage Image_GameEnd[3];
	TextureImage Image_Garbage[2];
	TextureImage Image_Environment[8];
	TextureImage Image_WaterFlow[10];
	Sprite * Numbers[2];									// Textures for numbers

	int WaterFlowIndex;									// To control the animation for water flow
	int BananaIndex;											// To control which banana of the Banana Object2D array
	int CountDownIndex;									// To control which image to show for couting down before game starts

	float GameEndTime;									// How long to display game end page
	float CountDownTime;								// Count down time before game starts
	float GameTime;											// Time left for the game to go
	Vector2D<float> MaxHeight;						// Max height players can jump
	float MaxSpeed;											// Max speed for players to move at
	
	// Background moving animation
	float BG_Moved;											// To keep track how much distance background moved
	bool BG_MoveLeft;										// To control which side background moving towards
	
public:
	CatchTheGarbage();
	void draw();
	void update();
	void reset();
	void freeResource();
	void loadResource();
	void handleKeyboard(int key, int x, int y);
	void handleKeyboardUp(int key, int x, int y);
	void handleKeyboardSpecial(int key, int x, int y);
	void getMid(int &x, int &y);
	void handleMouseClick(int button, int state, int x, int y);
	void handleMouseMove(int x, int y);

	// Update functions
	void AIUpdate();
	void Player1Update();
	void Player2Update();
	void GarbageUpdate();
	void BananaUpdate();
	void BonusUpdate();

	// AI movement
	void AIMovement(int key, int x, int y);
};